class Solution {
public:
    string countAndSay(int n)
    {
        string ret = "1";

        for (int i = 1;i < n;i++)
        {
            string emp;
            int len = ret.size();
            for (int left = 0, right = 0;right < len;)
            {
                while (right < len && ret[left] == ret[right])
                {
                    right++;
                }
                emp += to_string(right - left) + ret[left];
                left = right;
            }
            ret = emp;
        }
        return ret;
    }
};